package com.hlmc.service;

import com.hlmc.dao.DS_detailDao;
import com.hlmc.entity.Banner;
import com.hlmc.entity.DS360_dt;
import com.hlmc.entity.RankVideo;
import com.hlmc.entity.VideoCover;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("query_360")
public class Query_360_Service implements DS_detailDao {
    @Resource
    private DS_detailDao dtDao;

    @Override
    public int add(DS360_dt ds360_dt) {
        return 0;
    }

    @Override
    public int addRank(RankVideo rankVideo) {
        return dtDao.addRank(rankVideo);
    }

    @Override
    public int del(DS360_dt ds360_dt) {
        return 0;
    }

    @Override
    public int update(DS360_dt ds360_dt) {
        return 0;
    }

    @Override
    public DS360_dt findOneById(Serializable Id) {
        return null;
    }

    @Override
    public List<DS360_dt> findAll() {
        return null;
    }

    @Override
    public List<DS360_dt> findByName(DS360_dt ds) {
        List<DS360_dt> dt=dtDao.findByName(ds);
        return dt;
    }

    @Override
    public List<VideoCover> findCover(DS360_dt dt) {
        List<VideoCover> cover=dtDao.findCover(dt);
        return cover;
    }

    @Override
    public VideoCover findHotByTitle(Map<String,String> map) {
        return dtDao.findHotByTitle(map);
    }

    @Override
    public RankVideo findHot(String p_title) {
        return dtDao.findHot(p_title);
    }

    @Override
    public DS360_dt findAllByUrl(String image) {
        DS360_dt dt=dtDao.findAllByUrl(image);
        return dt;
    }

    @Override
    public List<VideoCover> findVideoPage(Map<String,Object> map) {
        List<VideoCover> list=dtDao.findVideoPage(map);
        return list;
    }

    @Override
    public int findCoverNum(DS360_dt ds) {
        int totalRecord=0;
        totalRecord=dtDao.findCoverNum(ds);
        return totalRecord;
    }

    @Override
    public List<VideoCover> findVideoByTitle(Map<String,String> map) {

        List<VideoCover> list=new ArrayList<VideoCover>();
        list=dtDao.findVideoByTitle(map);
        return list;
    }

    @Override
    public List<RankVideo> findBanner() {
        List<RankVideo> list=new ArrayList<RankVideo>();
        list=dtDao.findBanner();
        return list;
    }

    @Override
    public int addBanner(Banner banner) {
        dtDao.addBanner(banner);
        return 0;
    }

    @Override
    public List<Banner> findBner() {
        List<Banner> banners=new ArrayList<Banner>();
        banners=dtDao.findBner();
        return banners;
    }

    @Override
    public int updateHot(String title) {
        String bb[]={"tv","dy","dm"};
        for (int j=0;j<3;j++) {
            RankVideo rankVideo = dtDao.findHot(bb[j]);
            //List<VideoCover> listCover=new ArrayList<VideoCover>();
            String array[] = rankVideo.getVtitle().split(",");
            for (int i = 0; i < array.length; i++) {
                dtDao.updateHot(array[i]);
            }
        }
       return 0;
    }

    @Override
    public List<VideoCover> findHot1() {
        List<VideoCover> list=new ArrayList<VideoCover>();
        list=dtDao.findHot1();
        return list;
    }

    public int addBanner1() {
        List<RankVideo> list=new ArrayList<RankVideo>();
        list=dtDao.findBanner();
        for(int i=0;i<3;i++) {
            Map<String,String> map=new HashMap<String, String>();
           String ts= list.get(i).getVtitle();
           System.out.println(ts);
            String[] array =ts.split(",");
            String cat = list.get(i).getPtitle();
            map.put("v_title",array[0]);
            map.put("category",cat);
            String image=dtDao.findHotByTitle(map).getImage();
            Banner banner=new Banner(array[0],image);
            addBanner(banner);
            Map<String,String> map1=new HashMap<String, String>();
            map1.put("v_title",array[1]);
            map1.put("category",cat);
            String image1=dtDao.findHotByTitle(map1).getImage();
            Banner banner1=new Banner(array[1],image1);
            addBanner(banner1);
        }
        return  0;
    }

}
